package com.zhang.widget;

import com.zhang.activity.ListActivity;
import com.zhang.little_sample.R;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.text.format.Time;
import android.widget.RemoteViews;
import android.widget.Toast;

public class FirstWidget extends AppWidgetProvider {
	private String[] months={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};  
    private String[] days={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};  
    @Override  
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,  
            int[] appWidgetIds) {  
        // TODO Auto-generated method stub  
          
        RemoteViews remoteViews=new RemoteViews(context.getPackageName(), R.layout.firstwidget);  
        Time time=new Time();  
        time.setToNow();  
        String month=time.year+" "+months[time.month];  
        remoteViews.setTextViewText(R.id.txtDay, new Integer(time.monthDay).toString());  
        remoteViews.setTextViewText(R.id.txtMonth, month);  
        remoteViews.setTextViewText(R.id.txtWeekDay, days[time.weekDay]);  
        Intent intent=new Intent("com.zhang.widget.click");  
        PendingIntent pendingIntent=PendingIntent.getBroadcast(context, 0, intent, 0);  
 //     remoteViews.setOnClickPendingIntent(R.id.layout, pendingIntent);  
        Intent fullIntent=new Intent(context,ListActivity.class);
        PendingIntent Pfullintent=PendingIntent.getActivity(context, 0, fullIntent, 0);
        remoteViews.setOnClickPendingIntent(R.id.layout,Pfullintent);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
        super.onUpdate(context, appWidgetManager, appWidgetIds);  
    }  
      
    @Override  
    public void onReceive(Context context, Intent intent) {  
        // TODO Auto-generated method stub  
        super.onReceive(context, intent);  
        if(intent.getAction().equals("com.zhang.widget.click")){  
            Toast.makeText(context, "点击了widget日历", Toast.LENGTH_SHORT).show();
        }  
    }  
}
